<template>
  <div>
    <div @click="modalOpen = true">
      <el-card :body-style="{ padding: '0px' }">
        <img :src="imgUrl" class="image" />
      </el-card>
    </div>
    <teleport to="body">
      <div v-if="modalOpen" class="modal">
        这是一个弹窗
        <button @click="modalOpen = false">X</button>
      </div>
    </teleport>
  </div>
</template>

<script>
export default {
  name: "Modal",
  data() {
    return {
      modalOpen: true,
    };
  },
  created() {
    let urlTemp = "static/gzh.jpg";
    this.imgUrl = require("@/" + urlTemp);
  },
};
</script>

<style>
.modal {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.modal div {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: white;
  width: 300px;
  height: 300px;
  padding: 5px;
}
</style>
